/*
 * Copyright 2014 NAVER Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.ideal.ete.collector.dao.Impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.hadoop.hbase.client.Scan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

import com.ideal.ete.collector.application.CenterInfo;
import com.ideal.ete.collector.dao.CenterInfoDao;
import com.ideal.ete.collector.hbase.HBaseTables;
import com.ideal.ete.collector.vo.AgentInfo;
import com.ideal.hbase.client.HbaseOperations;
import com.ideal.hbase.client.core.mapper.RowMapper;

/**
 * @author netspider
 * @author emeroad
 */
@Repository
public class CenterInfoDaoImpl implements CenterInfoDao {



    @Autowired
    private HbaseOperations hbaseOperations;

  
    @Autowired
	 @Qualifier("centerInfoMapper")
	 private RowMapper<List<CenterInfo>> centerInfoMapper;
	 

/*    @Autowired
    @Qualifier("agentIdMapper")
    private RowMapper<List<String>> agentIdMapper;*/



	@Override
	public List<CenterInfo> getCenterInfosByCenter(String center) {
//		 HbaseOperations hbaseOperations = HbaseTemplate.INSTANCE;
		
		 List<CenterInfo> list = hbaseOperations.get(HBaseTables.CENTERINFO, center, centerInfoMapper);
		return list;
	}

	@Override
	public List<CenterInfo> getAllCenterInfos() {
		Scan scan = new Scan();
        scan.setCaching(30);
//        HbaseOperations hbaseOperations = HbaseTemplate.INSTANCE;
        List<List<CenterInfo>> find = hbaseOperations.find(HBaseTables.CENTERINFO, scan, centerInfoMapper);
        List<CenterInfo> centerInfos = new ArrayList<>();
        for (List<CenterInfo> result : find) {
        	centerInfos.addAll(result);
        }
        return centerInfos;
	}

	@Override
	public CenterInfo getAgentInfoByAgentId(String agentId, String center) {
		List<CenterInfo> list = hbaseOperations.get(HBaseTables.CENTERINFO, center, "C", agentId, centerInfoMapper);
		return list.get(0);
	}

	@Override
	public List<CenterInfo> getCenterByAgentId(String agentId) {
		 List<List<CenterInfo>> find = hbaseOperations.find(HBaseTables.CENTERINFO, "C",centerInfoMapper);
		return null;
	}
    
  
}
